import { anyFn } from "@/common/const";
import { throttle } from "lodash-es";
// 设置rem的大小
const resizeRemCb = throttle(function setRem() {
  const screenWidth = document.documentElement.clientWidth;
  let currentFontSize = (screenWidth * 10) / 1920;
  currentFontSize = currentFontSize > 6.5 ? currentFontSize : 6.5;
  document.documentElement.style.fontSize = currentFontSize + "px";
}, 100);

window.addEventListener("resize", resizeRemCb);
resizeRemCb();

/** 辅助 useRem 的缓存数组 */
const resizeCbArr: anyFn[] = [];
const resizeCb = throttle(function getRem() {
  resizeCbArr.forEach((cb) => cb?.(parseFloat(document.documentElement.style.fontSize)));
}, 100);

window.addEventListener("resize", resizeCb);